/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax;

import deatax.mode.GameMode;
import com.jogamp.opengl.util.FPSAnimator;
import deatax.card.CardManager;
import deatax.display.BoardRenderer;
import deatax.display.Camera;
import deatax.display.GUI;
import deatax.display.Light;
import deatax.display.miniboard.MiniBoard;
import deatax.display.miniboard.SelectedTileRenderer;
import deatax.log.ActionLog;
import java.awt.PopupMenu;
import java.awt.TrayIcon;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.JFrame;

/**
 *
 * @author pson
 */
public class GameData implements GLEventListener {

    public static int LOD_ANITALIASING_NICE = 256;
    public static int LOD_ANITALIASING = 128;
    public static int LOD_PARTICLES = 32;
    public static int LOD_FOG = 16;
    public static int LOD_KING = 4;
    public static int LOD_MODELS = 2;

    private TrayMenu tray;

    private JFrame frame;
    private GLCanvas display;
    private BoardRenderer render;
    private MiniBoard miniboard;
    private SelectedTileRenderer selectedTileRenderer;
    private Camera camera;
    private GUI gui;
    private StateManager state;
    private ActionLog log;
    private CardManager cards;
    private Dice dice;
    private PlayerRoster roster;
    private Map map;
    private GameManager game;
    private GameMode mode;
    private Player self;
    private List<Light> lights = new ArrayList<Light>();
    private LinkedHashMap<String, File> resources = new LinkedHashMap<String, File>();

    private static int detailLevel = BoardRenderer.LOD_ANITALIASING | BoardRenderer.LOD_FOG | BoardRenderer.LOD_MODELS | BoardRenderer.LOD_ANITALIASING_NICE | BoardRenderer.LOD_KING | BoardRenderer.LOD_PARTICLES;

    public GameData() {
    }

    public void addResource(String s, File r) {
        resources.put(s, r);
    }
    
     public File getResource(String s) {
        return resources.get(s);
    }
     
    public GLCanvas getDisplay() {
        return display;
    }

    public void setDisplay(GLCanvas display) {
        this.display = display;
    }

    public JFrame getFrame() {
        return frame;
    }

    public void setFrame(JFrame frame) {
        this.frame = frame;
    }

    public Camera getCamera() {
        return camera;
    }

    public void setCamera(Camera camera) {
        this.camera = camera;
    }

    public GameMode getMode() {
        return mode;
    }

    public void setMode(GameMode mode) {
        this.mode = mode;
    }

    public Player getSelf() {
        return self;
    }

    public void setSelf(Player self) {
        this.self = self;
    }

    public Dice getDice() {
        return dice;
    }

    public void setDice(Dice dice) {
        this.dice = dice;
    }

    public GUI getGui() {
        return gui;
    }

    public void setGui(GUI gui) {
        this.gui = gui;
    }

    public Map getMap() {
        return map;
    }

    public void setMap(Map map) {
        this.map = map;
    }

    public BoardRenderer getRender() {
        return render;
    }

    public void setRender(BoardRenderer render) {
        this.render = render;
    }

    public MiniBoard getMiniboard() {
        return miniboard;
    }

    public void setMiniboard(MiniBoard miniboard) {
        this.miniboard = miniboard;
    }

    public PlayerRoster getRoster() {
        return roster;
    }

    public void setRoster(PlayerRoster roster) {
        this.roster = roster;
    }

    public GameManager getGame() {
        return game;
    }

    public void setGame(GameManager game) {
        this.game = game;
    }

    public ActionLog getLog() {
        return log;
    }

    public CardManager getCards() {
        return cards;
    }

    public void setCards(CardManager cards) {
        this.cards = cards;
    }

    public void setLog(ActionLog log) {
        this.log = log;
    }

    public StateManager getState() {
        return state;
    }

    public void setState(StateManager state) {
        this.state = state;
    }

    public void start() {
//        Animator a = new Animator(display);
        FPSAnimator a = new FPSAnimator(display, 60);
        a.start();
    }

    @Override
    public void init(GLAutoDrawable glad) {
        if (state.currentState() != null) {
            state.currentState().init(glad);
        }
    }

    @Override
    public void dispose(GLAutoDrawable glad) {
        if (state.currentState() != null) {
            state.currentState().dispose(glad);
        }
    }

    @Override
    public void display(GLAutoDrawable glad) {
        if (state.currentState() != null) {
            state.currentState().display(glad);
        }
    }

    @Override
    public void reshape(GLAutoDrawable glad, int i, int i1, int i2, int i3) {
        if (state.currentState() != null) {
            state.currentState().reshape(glad, i, i1, i2, i3);
        }
    }
    
    public void nextPlayerTurn() {
        roster.nextPlayer();
    }
    
    public Player getCurrentPlayer() {
        return roster.getCurrentPlayer();
    }

    public void addLight(Light l){
        lights.add(l);
    }

    public void removeLight(Light l){
        lights.remove(l);
    }

    public List<Light> getLights() {
        return lights;
    }

    public static int getDetailLevel() {
        return detailLevel;
    }

    public static boolean checkLOD(int type){
        return (detailLevel & type) == type;
    }

    public static void incLOD(){
        if(detailLevel > 1024) return;
        detailLevel = (detailLevel << 1) + 1;
    }

    public static void decLOD(){
        if(detailLevel < 4) return;
        detailLevel = detailLevel >> 1;
    }

    /**
     * @return the selectedTileRenderer
     */
    public SelectedTileRenderer getSelectedTileRenderer() {
        return selectedTileRenderer;
    }

    /**
     * @param selectedTileRenderer the selectedTileRenderer to set
     */
    public void setSelectedTileRenderer(SelectedTileRenderer selectedTileRenderer) {
        this.selectedTileRenderer = selectedTileRenderer;
    }

    void setTray(TrayMenu trayMenu) {
        this.tray = trayMenu;
    }

    public TrayMenu getTray() {
        return tray;
    }

    


}
